package com.augurit.wf.common.convertor;

import java.util.ArrayList;
import java.util.List;

import org.jbpm.api.history.HistoryTask;
import org.jbpm.api.task.Task;

import com.augurit.wf.common.form.TraceRecord;


public class TraceRecordConverter {
	
	public static TraceRecord convertTaskToRecord(Task task){
		TraceRecord record =  null;
		if(task != null ){
			record = new TraceRecord();
			
			record.setActivityName(task.getActivityName());
			record.setCreateDate(task.getCreateTime());
			record.setAssignee(task.getAssignee());
			record.setStatus("正在办理");
		}
		return record;
	}

	public static List<TraceRecord> convertTaskListToRecordList(List<Task> taskList){
		 List<TraceRecord> recordList = null;
		 if(taskList != null && taskList.size()>0){
			 recordList = new ArrayList<TraceRecord>();
			 for(Task task :taskList){
				 TraceRecord record = convertTaskToRecord(task);
				 recordList.add(record);
			 }
		 }
		 return recordList;
	}
	
	public static List<HistoryTask> execuldUnComplementedTask(List<HistoryTask> list){
		List<HistoryTask> result = null;
		if(list != null && list.size()>0){
			result = new ArrayList<HistoryTask>();
			for(HistoryTask task :list){
				if(task.getState() != null && task.getState().equals("completed"))
					result.add(task);
			}
		}
		return result;
	}
	
}
